#include "TestState.h"
#include <OgreTextureUnitState.h>
/*

#include "Character.h"
#include "Inventory.h"
#include <irrKlang.h>
#include "Weapon.h"

using namespace irrklang;
using namespace Ogre;

TestState* TestState::mTestState;

void TestState::enter( void ) {
    mRoot             = Root::getSingletonPtr();
    mOverlayMgr       = OverlayManager::getSingletonPtr();
    mInputDevice      = InputManager::getSingletonPtr()->getKeyboard();
	mMouseOverlay     = mOverlayMgr->getByName( "Overlay/MousePointer" );
	mMousePointer     = mOverlayMgr->getOverlayElement( "MousePointer/Pointer" );
	mSceneMgr         = mRoot->getSceneManager( "ST_GENERIC" );
	engine			  = createIrrKlangDevice();
	curSelectObj	= NULL;

	//Ogre::Overlay *inventory_bar = mOverlayMgr->getByName( "Allstates/Inventory" );
	//toggleLine = false;

	//Ogre::Overlay *dialog = mOverlayMgr->getByName( "Allstates/Dialog" );
	//dialog->show();

    mMouseOverlay->show();
	OSMScene oScene;

	//NxOgre
	nxWorld = new NxOgre::World();
	nxScene = nxWorld->createScene("Main",mSceneMgr,"gravity: yes, floor: no");
	agMainPlayer = nxScene->createActorGroup("mainplayer");

	// Maakt OSMScene met nieuwe sceneMgr
	oScene = OSMScene(mSceneMgr,  mRoot->getAutoCreatedWindow());
	oScene.setGameLevel(this);
	oScene.initialise("level_01.osm", NULL, nxWorld, nxScene);
	oScene.createScene();

	//nxScene = oScene.getNxScene();

	if( oScene.getCameraList().size() > 0 ) {
		mCamera = oScene.getCameraList().front();
		mViewport = oScene.getCameraList().front()->getViewport();
	} else {
		mCamera = mSceneMgr->createCamera( "TestCamera" );
		mViewport = mRoot->getAutoCreatedWindow()->addViewport( mCamera );
	}

	// Create RaySceneQuery
	mRaySceneQuery = mSceneMgr->createRayQuery(Ray());
	this->getAstarManager()->setGameLevel( this );

	mCamera->setPosition( 0, 0, 0 );
	mCamera->lookAt( 0, 0, 0 );

	//Character *character = new Character();
	//character->setModel( "Mainperson", "fish.mesh" );
	//character->setScale(20, 20, 20);
	//character->setPosition(100, 0, 100);
	
	//character->getInventory()->setOverlay( inventory_bar );
	//GameManager::getSingletonPtr()->addCharacter( character );
	//inventory_bar->show();

	// possibilities on creating Bodies
	// nxScene->createBody("nameOfBody;meshName.mesh", ....);	// creating new entity
	// nxScene->createBody("nameOfBody;(entity) nameOfEntity", ....); // using existed entity
	
	// specific position and direction using NxOgre::Pose
	//NxOgre::Pose(Vector3(9, -3, 0), Quaternion(Degree(90), Vector3::UNIT_Z));

	//mahninja = nxScene->createBody("NxNinja; ninja.mesh", new NxOgre::CubeShape(20, 100, 20), Vector3(0, 10, 0), "mass: 10");
	//mahninja->setGroup(agMainPlayer);

	//myHitReport *chr = new myHitReport();
	//NxOgre::CharacterController cc = NxOgre::CharacterController();
	//cc->addHitReport(chr);

	// A Character
	//NxOgre::CharacterParams cp;
	//cp.setToDefault();
	//cp.mSlopeLimit = 90;
	//mahchar = nxScene->createCharacter("NxNinja", NxOgre::Pose( Vector3( -100, 10, -100 ), Quaternion(Degree(-180), Vector3::UNIT_Z)), cp); // dunno why Pose is ignored
	//mahchar = nxScene->createCharacter("NxNinja", Vector3(-100,10,-100), cp);
	//mahchar->attachMesh("ninja.mesh");
	//mahchar->createNode();

	//cc->_registerCharacter("NxNinja");

	//Ogre::AnimationState *animation = mahchar->getEntity()->getAnimationState("Idle2");
	//animation->setEnabled( true );
	//animation->setLoop( true );
	
	//nxWorld->createDebugRenderer(mSceneMgr); // need to rebuild the lib with debugger enabled

}

void TestState::exit( void ) {
	//mRaySceneQuery->clearResults();
	//this->getAstarManager()->clean();

	//nxWorld->destroyScene("Main"); //or just delete all: delete nxWorld;
	//nxWorld->destroyDebugRenderer();
	delete nxWorld;
	mMouseOverlay->hide();
    mSceneMgr->clearScene();
    mSceneMgr->destroyAllCameras();
    mRoot->getAutoCreatedWindow()->removeAllViewports();
}

void TestState::pause( void ) {
	mMouseOverlay->hide();
}

void TestState::resume( void ) {
	mMouseOverlay->show();
}

void TestState::update( unsigned long lTimeElapsed ) {

	//mCamera->lookAt(mahchar->getNode()->getPosition());
	
	nxWorld->simulate(lTimeElapsed);
	nxWorld->render(lTimeElapsed);
	
}

void TestState::keyPressed( const OIS::KeyEvent &e ) {

	if( e.key == OIS::KC_ESCAPE ) {
		this->requestShutdown();
	}else if( e.key == OIS::KC_F1 ) {
		// show lines
	}else if(e.key == OIS::KC_W){
		//force = Vector3(1000,0,0);
		//mahchar->addMovement(NxOgre::Character::DR_Forward);
		//mahchar->setDirection(Degree(90));
	}else if(e.key == OIS::KC_S){
		//force = Vector3(-1000,0,0);
		//mahchar->addMovement(NxOgre::Character::DR_Backward);
	}else if(e.key == OIS::KC_D){
		//force = Vector3(0,0,1000);
		//mahninja->setGlobalOrientation( mahninja->getGlobalOrientation() + Quaternion(Degree(0.001), Vector3::UNIT_Y) );
		//mahninja->addTorque(Vector3(10, 0, 0));
		//mahchar->addMovement(NxOgre::Character::DR_StepRight);
	}else if(e.key == OIS::KC_A){
		//force = Vector3(0,0,-1000);
		//mahninja->setGlobalOrientation( mahninja->getGlobalOrientation() + Quaternion(Degree(-0.001), Vector3::UNIT_Y) );
		//mahninja->addTorque(Vector3(-10, 0, 0));
		//mahchar->addMovement(NxOgre::Character::DR_StepLeft);
	}else if(e.key == OIS::KC_SPACE){
		//mahchar->addMovement(NxOgre::Character::DR_Jump_Up);
		//force = Vector3(0,4000,0);
	}
	
}

void TestState::keyReleased( const OIS::KeyEvent &e ) {

	Vector3 force;
	force = Vector3(0,0,0);

	//if( e.key == OIS::KC_SPACE ) {
		//this->playMusic( "test.mp3" );
    //}
	//else 


	//mahninja->addForce(force);
}

void TestState::mouseMoved( const OIS::MouseEvent &e ) {
    const OIS::MouseState &mouseState = e.state;
	mMousePointer->setTop( mouseState.Y.abs );
	mMousePointer->setLeft( mouseState.X.abs );
}

void TestState::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ) {
	if( this->mouse_Button_clicked == OIS::MB_Right ) {
		/*
		std::vector<GameObject*>::iterator it;
		it = objects.begin();
		while( it != objects.end() ) {
			if( (*it)->getName() == this->mouse_Object_clicked ) {
				if( (*it)->isInventoryItem() ) {
					if( (*it)->getType() == "weapon" ) {
						//Weapon *weapon = static_cast<Weapon*>(this->getInventoryItem( "sign" ));
						//Character *c = GameManager::getSingletonPtr()->getCharacter( this->mouse_Object_clicked );
						//weapon->pickUp( c );
					}
				}
			}
		}*//*
	}
}

TestState* TestState::getSingletonPtr( void ) {
    if( !mTestState ) {
        mTestState = new TestState();
    }

    return mTestState;
}
*/